
// const isN = require("../utils/util")
 const isN = function(obj) {
  return obj === undefined || obj === null
}
class EnumItem {
  constructor(object) {
    this.key = object.key
    this.value = object.value
    this.name = object.name
  }
  equal(keyOrValue) {
    return this.key === keyOrValue || this.value === keyOrValue
  }
}
EnumItem.prototype.valueOf = function() {
  return this.value
}
class Enum {
  constructor(enumArr) {
    this._enum = {}
    for (const item of enumArr) {
      this._enum[item.key] = new EnumItem(item)
      Object.defineProperty(this, item.key, {
        value: this._enum[item.key]
      })
    }
  }
  getEnum() {
    return this._enum
  }
  get(keyOrValue) {
    if (!isN(this._enum[keyOrValue])) {
      return this._enum[keyOrValue]
    } else {
      for (const key in this._enum) {
        if (this._enum.hasOwnProperty(key)) {
          if (keyOrValue === this._enum[key].value) {
            return this._enum[key]
          }
        }
      }
      return null
    }
  }
  getName(keyOrValue) {
    const tempEnum = this.get(keyOrValue)
    return tempEnum ? tempEnum.name : null
  }
  valueIsIn(value, keyOrValues = []) {
    let temp
    for (const keyOrValue of keyOrValues) {
      temp = this.get(keyOrValue)
      if (temp && temp.value === value) {
        return true
      }
    }
    return false
  }
  valueIsNotIn(value, keyOrValues = []) {
    let temp
    for (const keyOrValue of keyOrValues) {
      temp = this.get(keyOrValue)
      if (temp && temp.value === value) {
        return false
      }
    }
    return true
  }
}
Enum.prototype.valueOf = function() {
  return this._enum
}
export default Enum

export const MARKET_EASY = new Enum([
	{
	  key: '0',
	  value: '0',
	  name: '未支付'
	},{
	  key: '1',
	  value: '1',
	  name: '待发货'
	},{
	  key: '2',
	  value: '2',
	  name: '已发货'
	},{
	  key: '3',
	  value: '3',
	  name: '已收货'
	},{
	  key: '4',
	  value: '4',
	  name: '已评价'
	},{
	  key: '5',
	  value: '5',
	  name: '已完成'
	},{
	  key: '6',
	  value: '6',
	  name: '退款中'
	},{
	  key: '7',
	  value: '7',
	  name: '已退款'
	},
	{
	  key: '8',
	  value: '8',
	  name: '已关闭'
	}
])


export const PAY_TYPE = new Enum([
	{
	  key: '1',
	  value: '1',
	  name: '微信'
	},{
	  key: '2',
	  value: '2',
	  name: '支付宝'
	},{
	  key: '3',
	  value: '3',
	  name: '货到付款'
	}
])

export const REFUND_TYPE = new Enum([
	{
	  key: '1',
	  value: '1',
	  name: '售后待处理'
	},{
	  key: '2',
	  value: '2',
	  name: '售后处理中'
	},{
	  key: '3',
	  value: '3',
	  name: '售后完成'
	},{
	  key: '4',
	  value: '4',
	  name: '售后拒绝'
	},{
	  key: '5',
	  value: '5',
	  name: '售后取消'
	},{
	  key: '6',
	  value: '6',
	  name: '货物已退到门店'
	}
])